/*     */ package com.qmsk.business.store.checkstockbill.controller;
/*     */ 
/*     */ import com.qmsk.business.store.checkstockDtl.dao.CheckStockDtlDao;
/*     */ import com.qmsk.business.store.checkstockbill.dao.CheckStockBillDAO;
/*     */ import com.qmsk.business.store.instockbill.service.InStockBillService;
/*     */ import com.qmsk.business.store.outstockbill.service.OutStockBillService;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadManyRows;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"checkStockBill"})
/*     */ public class CheckStockBillController
/*     */ {
/*  38 */   private static final Logger logger = Logger.getLogger(CheckStockBillController.class);
/*     */ 
/*     */   @Autowired
/*     */   private CheckStockBillDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private CheckStockDtlDao dtlDao;
/*     */ 
/*     */   @Autowired
/*     */   private OutStockBillService outStockBillService;
/*     */ 
/*     */   @Autowired
/*     */   private InStockBillService inStockBillService;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  55 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  57 */       Map params = new HashMap();
/*  58 */       MapUtils.addToMap(params, "no", 
/*  59 */         RequestUtils.getString(request, "no"));
/*  60 */       MapUtils.addPercentToMap(params, "maker", 
/*  61 */         RequestUtils.getString(request, "maker"));
/*  62 */       MapUtils.addPercentToMap(params, "firstChecker", 
/*  63 */         RequestUtils.getString(request, "firstChecker"));
/*  64 */       MapUtils.addPercentToMap(params, "checker", 
/*  65 */         RequestUtils.getString(request, "checker"));
/*  66 */       MapUtils.addToMap(params, "status", 
/*  67 */         RequestUtils.getInt(request, "status"));
/*  68 */       MapUtils.addToMap(params, "dtMakeStart", 
/*  69 */         RequestUtils.getDate(request, "dtMakeStart"));
/*  70 */       MapUtils.addToMap(params, "dtCreateEnd", 
/*  71 */         RequestUtils.getDate(request, "dtCreateEnd"));
/*  72 */       GsonEbRst gsonEbRst = this.dao.getGsonOfInStoreParams(params, nPageIdx, 
/*  73 */         nPageSize);
/*  74 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  76 */       logger.error(e);
/*  77 */       ResponseUtils.setErrorMsgResponse(
/*  78 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/*  86 */       GsonEbRst gsonEbRst = this.dao.getGsonOfId(id);
/*  87 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  89 */       logger.error(e);
/*  90 */       ResponseUtils.setErrorMsgResponse(
/*  91 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/dtlId/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListDtlId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/*  99 */       GsonEbRst gsonEbRst = this.dtlDao.getGsonOfId(id);
/* 100 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 102 */       logger.error(e);
/* 103 */       ResponseUtils.setErrorMsgResponse(
/* 104 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 122 */       int nResult = 0;
/* 123 */       Long id = null;
/* 124 */       String billNo = null;
/* 125 */       String sData = RequestUtils.getStringOfData(request);
/* 126 */       String sInstoreDtl = RequestUtils.getString(request, 
/* 127 */         "checkstockDtl");
/* 128 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 129 */       ParserDataSetJson p_dtl = ParserDataSetJson.fromString(sInstoreDtl);
/*     */       Iterator localIterator;
/*     */       GsonHeadOneRow r;
/* 131 */       if ((p != null) && (p.isExistsInsertRows())) {
/* 132 */         billNo = this.dao.getMaxBillNo(shopId);
/* 133 */         for (localIterator = p.getListInsertRows().iterator(); localIterator.hasNext(); ) { r = (GsonHeadOneRow)localIterator.next();
/* 134 */           r.autoAddHeadData("billNo", billNo);
/*     */         }
/* 136 */         nResult = this.dao.applyUpdates(p, "id");
/* 137 */         if (nResult > 0) {
/* 138 */           id = (Long)((GsonHeadOneRow)p.getListInsertRows().get(0))
/* 139 */             .getValueOfName("id");
/*     */         }
/*     */       }
/*     */ 
/* 143 */       if (id != null) {
/* 144 */         for (localIterator = p_dtl.getListInsertRows().iterator(); localIterator.hasNext(); ) { r = (GsonHeadOneRow)localIterator.next();
/* 145 */           r.autoAddHeadData("id", id);
/*     */         }
/* 147 */         nResult = this.dtlDao.applyUpdates(p_dtl);
/*     */       }
/* 149 */       if (nResult > 0) {
/* 150 */         DbConnection.commit();
/* 151 */         if (id != null) {
/* 152 */           String[] heads = { "id", "billNo" };
/* 153 */           Object[] datas = { id, billNo };
/* 154 */           ResponseUtils.toGsonEbRst(heads, datas, response);
/* 155 */           return; }
/* 156 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 157 */           RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 158 */           response);
/*     */ 
/* 160 */         return; }
/* 161 */       DbConnection.rollback();
/* 162 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 163 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 164 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 167 */       logger.error(e);
/* 168 */       DbConnection.rollback();
/* 169 */       ResponseUtils.setErrorMsgResponse(
/* 170 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 171 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 189 */       int nResult = 0;
/* 190 */       String sData = RequestUtils.getStringOfData(request);
/* 191 */       String sInstoreDtl = RequestUtils.getString(request, 
/* 192 */         "checkstockDtl");
/* 193 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 194 */       ParserDataSetJson p_dtl = ParserDataSetJson.fromString(sInstoreDtl);
/*     */ 
/* 196 */       if ((p != null) && (p.isExistsUpdateRows())) {
/* 197 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/* 199 */       if (p_dtl != null) {
/* 200 */         nResult += this.dtlDao.applyUpdates(p_dtl);
/*     */       }
/*     */ 
/* 203 */       if (nResult > 0)
/* 204 */         DbConnection.commit();
/*     */       else {
/* 206 */         DbConnection.rollback();
/*     */       }
/* 208 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 209 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 210 */         response);
/*     */     } catch (Exception e) {
/* 212 */       logger.error(e);
/* 213 */       DbConnection.rollback();
/* 214 */       ResponseUtils.setErrorMsgResponse(
/* 215 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 216 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 232 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 234 */       String[] strParams = id.split(",");
/* 235 */       int nResult = 0;
/*     */ 
/* 237 */       nResult = this.dtlDao.deleteByInId(strParams);
/*     */ 
/* 239 */       if (nResult > 0) {
/* 240 */         nResult = this.dao.deleteParams(strParams);
/*     */       }
/* 242 */       if (nResult > 0)
/* 243 */         DbConnection.commit();
/*     */       else {
/* 245 */         DbConnection.rollback();
/*     */       }
/* 247 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 248 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 249 */         response);
/*     */     } catch (Exception e) {
/* 251 */       DbConnection.rollback();
/* 252 */       logger.error(e);
/* 253 */       ResponseUtils.setErrorMsgResponse(
/* 254 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 255 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */     throws SQLException
/*     */   {
/* 273 */     int nResult = 0;
/* 274 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/*     */ 
/* 276 */     Long id = RequestUtils.getLong(request, "id");
/*     */     try
/*     */     {
/* 279 */       nResult = this.dao.updateStatusOfId(id).intValue();
/* 280 */       if (nResult > 0) {
/* 281 */         GsonHeadOneRow g = this.dao.getOneRowOfId(id);
/* 282 */         String billNo = (String)g.getValueOfName("billNo");
/* 283 */         GsonHeadManyRows outM = this.dtlDao.getManyRowsOutOfId(id);
/* 284 */         if ((outM != null) && (outM.isExistsData())) {
/* 285 */           for (int i = 0; i < outM.getDataLength(); ++i) {
/* 286 */             Double nums = ObjectComm.objectToDouble(outM
/* 287 */               .getValueOfName("nums", i));
/* 288 */             outM.setValueOfName("nums", i, Double.valueOf(Math.abs(nums.doubleValue())));
/*     */           }
/* 290 */           String outNo = this.outStockBillService.getOutNo(shopId);
/* 291 */           String[] outHead = { "shopId", "outTpId", 
/* 292 */             "outNo", "linkNo", "maker", "makeDate", "status", 
/* 293 */             "outDate" };
/* 294 */           Object[] outData = { shopId, Integer.valueOf(3), outNo, billNo, 
/* 295 */             userId, new Date(), Integer.valueOf(1), new Date() };
/*     */ 
/* 297 */           nResult = nResult + this.outStockBillService
/* 297 */             .insertOutBill(new GsonHeadOneRow(outHead, outData), outM).intValue();
/*     */         }
/*     */ 
/* 300 */         GsonHeadManyRows inM = this.dtlDao.getManyRowsInOfId(id);
/* 301 */         if ((outM != null) && (inM.isExistsData())) {
/* 302 */           String inNo = this.inStockBillService.getInNo(shopId);
/* 303 */           String[] inHead = { "shopId", "inTpId", 
/* 304 */             "inNo", "linkNo", "maker", "makeDate", "status", 
/* 305 */             "inDate" };
/* 306 */           Object[] inData = { shopId, Integer.valueOf(2), inNo, billNo, 
/* 307 */             userId, new Date(), Integer.valueOf(1), new Date() };
/*     */ 
/* 309 */           nResult = nResult + this.inStockBillService
/* 309 */             .insertOutBill(new GsonHeadOneRow(inHead, inData), inM).intValue();
/*     */         }
/*     */       }
/* 312 */       if (nResult > 0)
/* 313 */         DbConnection.commit();
/*     */       else {
/* 315 */         DbConnection.rollback();
/*     */       }
/* 317 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 318 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 319 */         response);
/*     */     } catch (Exception e) {
/* 321 */       DbConnection.rollback();
/* 322 */       logger.error(e);
/* 323 */       ResponseUtils.setErrorMsgResponse(
/* 324 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 325 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.checkstockbill.controller.CheckStockBillController
 * JD-Core Version:    0.5.3
 */